<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>

        // toString

        const res1 = Object.prototype.toString();
        console.log(res1)   // object object


        const n = 1;

        // 把this改成了字符串
        console.log(n.toString())




        const arr = [];
        console.log(Object.prototype.toString.call(arr));   // [object Array]


        const str = 'hi';
        console.log(Object.prototype.toString.call(str));   // [object String]

        console.log(Object.prototype.toString.call(1));

        console.log(Object.prototype.toString.call(true));

        console.log(Object.prototype.toString.call(null));

        console.log(Object.prototype.toString.call(undefined));




        function dataType(d) {
            const res = Object.prototype.toString.call(d);
            if (res === '[object String]') {
                return 'string'
            }
            if (res === '[object Number]') {
                return 'number'
            }
            if (res === '[object Boolean]') {
                return 'boolean'
            }
            if (res === '[object Array]') {
                return 'array'
            }
            if (res === '[object Null]') {
                return 'null'
            }
            if (res === '[object Object]') {
                return 'object'
            }
            // ....
        }

        console.log(dataType('1'))



        // Object.prototype.toString = function () {
        //     // 把实例化对象转成字符串
        //     return String(this)
        // }

        // Object.prototype.toString()    这里的this实际上不是指向实例化对象   而是指向prototype




        // function dog() { }
        // dog.aa = { a: 1 };

        // dog.aa.fn = function () {
        //     console.log(this)    // aa这个对象
        //     console.log(1)
        // }


        // dog.aa.fn();

    </script>

</body>

</html>